﻿using System;
using System.Data;
using System.Text;
using Token.Piker.BLL;

namespace Token.Piker.Web.Admin.Photo
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void pagerList_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack && !IsCallback)
            {
                BindData();
            }
        }

        private void BindData()
        {
            StringBuilder sb = new StringBuilder();

            if (textKeyword.Text.Trim() != string.Empty)
            {
                sb.AppendFormat("Descrip LIKE '%{0}%' AND ", textKeyword.Text.Trim());
            }
            sb.Append("(Album IS NULL OR Album = '')");

            PhotoBLL bll = new PhotoBLL();
            DataSet ds = bll.GetListByPage(sb.ToString(), "UploadTime DESC", pagerList.StartRecordIndex, pagerList.EndRecordIndex);
            dataList.DataSource = ds;
            dataList.DataBind();

            pagerList.RecordCount = bll.GetRecordCount(sb.ToString());
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}